package com.fanqiechaodan.singleton.singleton4;

/**
 * @author fanqiechaodan
 * @Classname Singleton
 * @Description
 */
public class Singleton {

    private Singleton() {
        // 私有构造函数
    }

    static enum SingletonEnum {
        /**
         * 枚举实例
         */
        INSTANCE;

        private Singleton singleton;

        /**
         * 私有构造函数,确保只有一个实例
         */
        private SingletonEnum() {
            singleton = new Singleton();
        }

        private Singleton getSingleton() {
            return singleton;
        }
    }

    /**
     * 对外暴露一个获取Singleton对象的静态方法
     *
     * @return
     */
    public static Singleton getInstance() {
        return SingletonEnum.INSTANCE.getSingleton();
    }

}
